package com.hxkj.controller;

import com.hxkj.domain.po.RankingManagement;
import com.hxkj.service.RankingManagementService;
import com.platform.common.dispatcher.util.ResultStructUtils;
import com.platform.common.domain.result.ParameterDataStruct;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import com.platform.common.domain.result.ResultPageStruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

/**
 * 排行榜控制器
 * <p>
 * Created by yaosy on 2018年7月2日15:48:51
 */
@RestController
@RequestMapping("/ranking")
public class RankingManagementController {

    private static final Logger LOGGER = LoggerFactory.getLogger(RankingManagementController.class);


    @Autowired
    private RankingManagementService rankingManagementService;


    /**
     * 查询排行榜接口
     * @param parameterDataStruct
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getlist", method = RequestMethod.POST, consumes = "application/json;charset=UTF-8")
    public Callable<ResultPageStruct<RankingManagement>> getList(@RequestBody ParameterDataStruct<RankingManagement> parameterDataStruct) throws Exception {
        return () -> ResultStructUtils.buildResultPageStruct(rankingManagementService.getlist(parameterDataStruct.getData() == null ?
                new RankingManagement() : parameterDataStruct.getData(), parameterDataStruct.getPageTo()), "param=value");
    }

    /**
     * 新建排行榜
     *
     * @param rankingManagement
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST,consumes  ="application/json;charset=UTF-8")
    public Callable<ResultMessageStruct> save(@RequestBody RankingManagement rankingManagement) {
        return ()-> rankingManagementService.save(rankingManagement);
    }

    /**
     * 批量删除排行榜
     *
     *
     * @param rankingManagement
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete",consumes  ="application/json;charset=UTF-8",method = RequestMethod.POST)
    public  Callable<ResultMessageStruct>  remove(@RequestBody RankingManagement rankingManagement) {
        return ()-> rankingManagementService.delete(rankingManagement);
    }

    /**
     * 获取单条排行榜
     *
     * @param rankingManagement
     * @throws Exception
     */
    @RequestMapping(value = "/get",consumes  ="application/json;charset=UTF-8",method = RequestMethod.POST)
    public  Callable<ResultDataStruct<RankingManagement>> get(@RequestBody RankingManagement rankingManagement) {
        return ()-> rankingManagementService.get(rankingManagement);
    }

    /**
     * 保存单条排行榜
     * @param rankingManagement
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/modify",consumes  ="application/json;charset=UTF-8",method = RequestMethod.POST)
    public  Callable<ResultMessageStruct>  modify(@RequestBody RankingManagement rankingManagement)  throws Exception{
        return ()-> rankingManagementService.modify(rankingManagement);
    }


}
